﻿using System.Data.Entity;
using Metro.Kashikoi.Service.Common.Entity;
using Metro.Kashikoi.ServiceContract.Storage;

namespace Metro.Kashikoi.Service.Storage.Entity
{
    /// <summary>
    /// This class implements the interface <c>IUnitOfWork</c>.
    /// </summary>
    class Context : ContextBase
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Context"/> class.
        /// </summary>
        public Context()
            : base("Storage")
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the inventory.
        /// </summary>
        /// <value>
        /// The inventory.
        /// </value>
        public IDbSet<Inventory> Inventory { get; set; }

        /// <summary>
        /// Gets or sets the inventory.
        /// </summary>
        /// <value>
        /// The inventory.
        /// </value>
        public IDbSet<Trigger> Trigger { get; set; }

        /// <summary>
        /// Gets or sets the inventory.
        /// </summary>
        /// <value>
        /// The inventory.
        /// </value>
        public IDbSet<Container> Container { get; set; }

        #endregion

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BinInventory>().HasOptional(o => o.Container).WithOptionalPrincipal();
            modelBuilder.Entity<BinInventory>().HasRequired(o => o.Trigger).WithRequiredPrincipal();
            base.OnModelCreating(modelBuilder);
        }
    }
}
